package com.gugee.tiktok.web.repository;


import com.gugee.tiktok.web.model.mysql.RankingEnterprise;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Optional;

public interface RankingEnterpriseRepository extends CrudRepository<RankingEnterprise,Long>,RankingEnterpriseExtRepository {

    @Query("SELECT IFNULL(MAX(update_time),0) FROM ranking_enterprise WHERE ranking_type = :rankingType ORDER BY update_time desc LIMIT 0,1")
    Long findUpdateTime(int rankingType);

    @Query("select DISTINCT(belong) from ranking_enterprise where ranking_type = :rankingType and belong > :startDate ORDER BY belong  DESC")
    List<Integer> findBelongDate(int rankingType, int startDate);

    @Query("select * from ranking_enterprise where uid = :uid and ranking_type = :rankingType and blogger_type = :bloggerType and belong = :date")
    Optional<RankingEnterprise> findBloggerRanking(long uid, int rankingType, int bloggerType, int date);
}
